<?php
require_once("Lastfm.php");
/**
 * Class related to data entered by the user
 * 
 * @author Magnus Stoveland <mstoveland@gmail.com>
 *  
 */
class ManualInput
{
    /**
     * Split string to an array
     *
     * @param string $string
     * @param string $separator
     * @return array exploded string
     */
    function split_string($string, $separator = ", ") {
        $string_array = explode($separator, $string);
        foreach($string_array as $artist) {
            $userMusic = new UserMusic();
            $userMusic->artist = $artist;
            $userMusic->weight = 100;
            $output[] = $userMusic;
        }
        return $output;
    }
    
    /**
     * Parse XML from http://ws.audioscrobbler.com with "SimpleXML" and return array with UserMusic-objects 
     * 
     * @param string $tag
     * @return array with UserMusic-objects
     */
    function read_tag_xml($tag) {
		// Parse the xml with the simplexml44 lib
		$impl = new IsterXmlSimpleXMLImpl();
		$tag = Lastfm::wsEncode($tag);
		$file = 'http://ws.audioscrobbler.com/1.0/tag/'.$tag.'/topartists.xml';
		if(!@fopen($file, "r")) {
		    trigger_error("Unknown tag: ".$tag, E_USER_WARNING);
		    return false;
		}
		$doc = $impl->load_file($file);
		foreach($doc->tag->artist as $artist_obj) {
		    $attribs = $artist_obj->attributes();
            $userMusic = new UserMusic();
            $userMusic->artist = $attribs['name'];
            $userMusic->weight = 100;
            $output[] = $userMusic;
		}
		return $output;
    }
}
?>